var AlagisMap = function(){
    var ALAGISMAP = null;
    function initAlagisHotArea(map) {
        alagis.source.EdushiMap.initHotArea({
           map: ALAGISMAP,
           http: "http://120.27.215.107:8081/hotArea",
           key: "",
           zoom: 14,
           zindex: 50,
           style: {
               fill: {
                   color: 'rgba(255,255,255,0.6)'
               },
               stroke: {
                   color: '#9B822D',
                   width: 2
               },
               text: {
                   font: '12px Calibri,sans-serif',
                   fill: {
                       color: '#000'
                   },
                   stroke: {
                       color: '#fff',
                       width: 3
                   }
               }
           }
       });
   }

   function initPointerMove(){

        ALAGISMAP.on('pointermove', function (evt) {
            if (evt.dragging) {
                return;
            }
            var pixel = evt.map.getEventPixel(evt.originalEvent);
            var hit = evt.map.hasFeatureAtPixel(pixel);
            if(hit){
                evt.map.getTargetElement().style.cursor ='pointer';
            }else{
                evt.map.getTargetElement().style.cursor =' url(/public/images/openhand.cur) 8 8, default';
            }
            
      });

   }

   function addHotAreaOverlay(){
        var container = document.getElementById('popup');
        var overlay = new alagis.Overlay(({
            element: container,
            autoPan: true,
            autoPanAnimation: {
                duration: 250
            }
        }));
        ALAGISMAP.addOverlay(overlay);
        ALAGISMAP.on('click', function (evt) {
            var features= new Array();
            var coordinate = evt.coordinate;
            var currentId = null;
            evt.map.forEachFeatureAtPixel(evt.pixel, function (feature) {
                 if(currentId !== feature.getId()){
                     features.push(feature);
                    currentId = feature.getId();
                 }
            });

            if (features.length === 1) {
              
              //  console.log(features[0].R);
                var name = features[0].get("name");
                var address = features[0].get("address");
                if(!address){
                    address = name;
                }

                overlay.setPosition(coordinate);
               // alagisUtil.mtoBaidu(features[0].get("centerx"),features[0].get("centery"),function(data){
                //    console.log(data);
                //});
            }else{

            }
        });
        
       

   }


    return{

        initAlagisMapEvent:function(map){
            ALAGISMAP = map
            addHotAreaOverlay();
            initAlagisHotArea();
            initPointerMove();
        }
    }
}();